/**
 * 用ToolTip开发的轻量Window，替代Ext.Window
 * 该组件去除tooltip的箭头和对具体组件的绑定。
 * 如果需要对某个对象绑定请使用回Ext.ToolTip
 * @class biAdhocNs.ToolTipWindow
 * @author chenzhuangwei
 * @extends Ext.ToolTip
 */
biAdhocNs.UXToolTipWindow = Ext.extend(Ext.ToolTip, {
	show : function() { // 修复展现tooltip问题
		if (this.anchor) {
			var showListeners = this.events['show'].listeners; // fix
			this.events['show'].listeners = [];
			this.showAt([-1000, -1000]);
			this.origConstrainPosition = this.constrainPosition;
			this.constrainPosition = false;
			this.anchor = this.origAnchor;
			this.events['show'].listeners = showListeners ;// fix
		}
		if(this.target){
			this.showAt(this.getTargetXY());
		}else{
			this.showAt([400,200]);
		}
		if (this.anchor) {
			this.syncAnchor();
			this.anchorEl.show();
			this.constrainPosition = this.origConstrainPosition;
		} else {
			this.anchorEl.hide();
		}
	},
	unbindTarget : function() { // 去除tooltip目标绑定事件
		if (this.target) {
			var tg = Ext.get(this.target);
			this.mun(tg, 'mouseover', this.onTargetOver, this);
			this.mun(tg, 'mouseout', this.onTargetOut, this);
			this.mun(tg, 'mousemove', this.onMouseMove, this);
		}
		this.target = null;

		if (this.anchor) {
			this.anchorTarget = null;
		}
	},
	// private
    onRender : function(ct, position){
        Ext.ToolTip.superclass.onRender.call(this, ct, position);
        this.anchorCls = 'x-tip-anchor-' + this.getAnchorPosition();
        this.anchorEl = this.el.createChild({
            cls: this.anchorCls
        });
        if(this.header)
        	this.header.dom.style.cursor = 'move';
    },
    // private
    onHide : function(){
        biAdhocNs.UXToolTipWindow.superclass.onHide.call(this);
        this.unbindTarget();
    }
});

Ext.reg('ux_tooltipwindow', biAdhocNs.UXToolTipWindow);